package com.teamwhole.modules.report.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.teamwhole.modules.report.entity.ScoreReport;
import com.teamwhole.modules.report.service.ScoreReportService;

@Component
@Path("/gcb/report/")
@Consumes("application/json;charset=utf-8")
@Produces("application/json;charset=utf-8")
public class ScoreReportResource {
	@Autowired
	private ScoreReportService scoreReportService;

	// 在列表中显示所有数据
	@Path("/GetFullStruct")
	@GET
	public List<ScoreReport> getFullStruct() {
		return scoreReportService.getFullStruct();
	}
	@Path("/GetGridStruct")
	@GET
	public List<ScoreReport> getGridStruct() {
		return scoreReportService.getGridStruct();
	}
	
	

	@Path("/GetScoreSum")
	@POST
	public List<ScoreReport> getScoreSum(ScoreReport report) {
		String sdate1 = report.getParamMap().get("date1").toString();
		String sdate2 = report.getParamMap().get("date2").toString();

		sdate1 = sdate1 + " 00:00:00";
		sdate2 = sdate2 + " 00:00:00";
		
		Date date1 = null;
		Date date2 = null;
		
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			date1 = sdf.parse(sdate1);
			date2 = sdf.parse(sdate2);
			Calendar c = Calendar.getInstance();
			c.setTime(date2);
			c.add(Calendar.HOUR, 24);
			date2 = c.getTime();
			
			report.getParamMap().put("date1", date1);
			report.getParamMap().put("date2", date2);
		} catch (ParseException e) {
			;// e.printStackTrace();
		}
		
		return scoreReportService.getScoreSum(report);
	}
	
	@Path("/GetScoreCount")
	@POST
	public List<ScoreReport> getScoreCount(ScoreReport report) {
		String fyear = report.getParamMap().get("fyear").toString();
		String fmonth = report.getParamMap().get("fmonth").toString();
		String tyear = report.getParamMap().get("tyear").toString();
		String tmonth = report.getParamMap().get("tmonth").toString();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		String sdateF = fyear + "-" + fmonth + "-01 00:00:00";
		String sdateT = tyear + "-" + tmonth + "-01 00:00:00";

		Date date1 = null;
		Date date2 = null;

		try {
			date1 = sdf.parse(sdateF);
			date2 = sdf.parse(sdateT);
			Calendar c = Calendar.getInstance();
			c.setTime(date2);
			c.add(Calendar.MONTH, 1);
			date2 = c.getTime();
		} catch (ParseException e) {
			;// e.printStackTrace();
		}

		report.getParamMap().put("date1", date1);
		report.getParamMap().put("date2", date2);

		return scoreReportService.getScoreCount(report);
	}

	@Path("/GetRegionScoreCount")
	@POST
	public List<ScoreReport> getRegionScoreCount(ScoreReport report) {
		String sdate1 = report.getParamMap().get("date1").toString();
		String sdate2 = report.getParamMap().get("date2").toString();

		sdate1 = sdate1 + " 00:00:00";
		sdate2 = sdate2 + " 00:00:00";
		
		Date date1 = null;
		Date date2 = null;
		
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			date1 = sdf.parse(sdate1);
			date2 = sdf.parse(sdate2);
			Calendar c = Calendar.getInstance();
			c.setTime(date2);
			c.add(Calendar.HOUR, 24);
			date2 = c.getTime();
			
			report.getParamMap().put("date1", date1);
			report.getParamMap().put("date2", date2);
		} catch (ParseException e) {
			;// e.printStackTrace();
		}
		
		return scoreReportService.getRegionScoreCount(report);
	}
	
	@Path("/GetScoreMonthReport")
	@POST
	public List<ScoreReport> getScoreMonthReport(ScoreReport report) {
		String syear = report.getParamMap().get("year").toString();
		String smonth = report.getParamMap().get("month").toString();

		String sdate1 = syear + "-"+smonth+"-01 00:00:00";
		
		Date date1 = null;
		Date date2 = null;
		
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			date1 = sdf.parse(sdate1);
			Calendar c = Calendar.getInstance();
			c.setTime(date1);
			c.add(Calendar.MONTH, 1);
			date2 = c.getTime();
			
			report.getParamMap().put("date1", date1);
			report.getParamMap().put("date2", date2);
		} catch (ParseException e) {
			;// e.printStackTrace();
		}
		
		return scoreReportService.getScoreMonthReport(report);
	}
	
	
}
